package com.example.controller;

import com.example.pojo.Announcement;
import com.example.pojo.Job;
import com.example.pojo.JobInfo;
import com.example.pojo.TakersJob;
import com.example.service.AnnouncementService;
import com.example.service.JobService;
import com.example.service.TakersJobService;
import com.example.util.ResponseWrapper;
import javafx.scene.chart.StackedBarChart;
import org.omg.CORBA.StringHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private TakersJobService takersJobService;

    @Autowired
    private JobService jobService;

    @Autowired
    private AnnouncementService announcementService;

    @GetMapping("/myWorks/{useridentityfer}")
    public ResponseWrapper<List<Job>> getMyJobs(@PathVariable Integer useridentityfer) {
        List<TakersJob> takersJobList = takersJobService.getJobs(useridentityfer);
        List<Job> jobList = jobService.getStudentAllJobs(takersJobList);
        for (Job job:jobList) {
            System.out.println("兼职："+job);
        }
        return ResponseWrapper.success(jobList);
    }

    @GetMapping("/announcements/{month}")
    public ResponseWrapper<List<Announcement>> getAnnouncements(@PathVariable int month) {
        List<Announcement> announcementList = announcementService.getAnnouncementListByMonth(month);
        return ResponseWrapper.success(announcementList);
    }

    @GetMapping("/allWork")
    public ResponseWrapper<List<Job>> getALLWorks() {
        List<Job> jobList = jobService.getAccessWorks();
        System.out.println("jobList"+jobList);
        return ResponseWrapper.success(jobList);
    }

    @GetMapping("/receiveWorks/{useridentityfer}/{username}/{jobId}")
    public ResponseWrapper<List<Job>> getReceiveWorks(@PathVariable Integer useridentityfer, @PathVariable String username, @PathVariable Integer jobId) {
        int one = takersJobService.insertOne(useridentityfer,username,jobId);
        if (one == 1){
            return ResponseWrapper.NULL_DATA_Success("该职位用户已申请");
        }else {
            jobService.updateJobToReceive(jobId);
            return ResponseWrapper.success();
        }
    }

    @GetMapping("/jobIsInWork/{useridentityfer}")
    public ResponseWrapper<Boolean> JobIsInWork(@PathVariable Integer useridentityfer){
        List<TakersJob> takersJobList = takersJobService.getJobs(useridentityfer);
        Boolean isSuccess = jobService.jobInWork(takersJobList);
        return ResponseWrapper.success(isSuccess);
    }
}
